/*
 * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * https://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.aabte.commons.rest.exception;


import com.aabte.commons.rest.enums.StandardErrorCode;
import com.aabte.commons.rest.errorcode.IApiErrorCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * REST API 请求异常类
 *
 * @author hubin
 * @since 2017-06-26
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class ApiException extends RuntimeException {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = -5885155226898287919L;

    private Integer status;
    private Long code;

    public ApiException() {
        this(StandardErrorCode.InternalServerError.getStatus(),
            StandardErrorCode.InternalServerError.getCode(),
            StandardErrorCode.InternalServerError.getMsg(), null);
    }

    public ApiException(String message) {
        this(StandardErrorCode.InternalServerError.getStatus(),
            StandardErrorCode.InternalServerError.getCode(), message, null);
    }

    public ApiException(IApiErrorCode errorCode) {
        this(errorCode.getStatus(), errorCode.getCode(), errorCode.getMsg(), null);
    }

    public ApiException(IApiErrorCode errorCode, Throwable cause) {
        this(errorCode.getStatus(), errorCode.getCode(), errorCode.getMsg(), cause);
    }

    public ApiException(Integer status, Long code, String message) {
        this(status, code, message, null);
    }

    public ApiException(Integer status, Long code, Throwable cause) {
        this(status, code, cause.getMessage(), cause);
    }

    public ApiException(Integer status, Long code, String message, Throwable cause) {
        super(message, cause);
        this.status = status;
        this.code = code;
    }

}
